package com.yudean.esb.dao.esb;

import com.yudean.esb.domain.esb.EsbRecvServicePackage;
import com.yudean.esb.mapper.esb.EsbRecvServicePackageMapper;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class EsbRecvServicePackageDao {
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(EsbRecvServicePackageDao.class);
    @Resource
    private EsbRecvServicePackageMapper esbRecvServicePackageMapper;

    public boolean insert(EsbRecvServicePackage pkg) {
        boolean result = false;
        try {
            esbRecvServicePackageMapper.insert(pkg);
            result = true;
        } catch (Exception e) {
            logger.error("EsbRecvServicePackageDao insert():e-{}", e.getMessage());
            result = false;
        }
        return result;
    }

    public void delete(EsbRecvServicePackage pkg) {
        esbRecvServicePackageMapper.delete(pkg);
    }

    public boolean insert(String transactionID, String packageID) {
        logger.debug("insert():request-{transactionID:{},packageID:{}}", transactionID, packageID);
        EsbRecvServicePackage pack = new EsbRecvServicePackage();
        pack.setTransactionID(transactionID);
        pack.setPackageID(packageID);
        return insert(pack);
    }

    public boolean insert(String transactionID, String packageID, String forceReplace) {
        logger.debug("insert():request-{transactionID:{},packageID:{}, forceReplace:{}}", transactionID, packageID, forceReplace);
        EsbRecvServicePackage pack = new EsbRecvServicePackage();
        pack.setTransactionID(transactionID);
        pack.setPackageID(packageID);
        if (forceReplace != null && forceReplace.equals("1")) {
            delete(pack);
        }
        return insert(pack);
    }
}
